<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2015/12/23 0023
 * Time: 上午 9:24
 */

//服务器端
//第一句话告诉浏览器返回的数据是xml格式，及编码
header("Content-Type: text/html;charset=utf-8");
//告诉浏览器不要缓存数据
header("Cache-Control: no-cache");

//接收数据
$cities=$_POST['city'];

//产生随机数 三个500-2000间的数
//$res='[{"price":"400"},{"price":"1000"},{"price":"2000"}]';
$res='[';
for($i=0;$i<count($cities);$i++){
//echo rand(500,2000);
    if($i==count($cities)-1){
        $res.='{"cityname":"'.$cities[$i].'","price":"'.rand(500,2000).'"}]';
    }else{
        $res.='{"cityname":"'.$cities[$i].'","price":"'.rand(500,2000).'"},';
    }
}
//file_put_contents("d:/mylog.log",$res."\r\n",FILE_APPEND);
echo $res;